package com.kaifamiao.list;

import java.util.ArrayList;
import java.util.List;

/**
 * void add( int index, E element )
 * E set( int index, E element )
 * E get( int index )
 * int indexOf( Object o )
 * int lastIndexOf( Object o )
 * E remove( int index )
 * List<E> subList( int fromIndex, int toIndex )
 */
public class ListInstanceMethods {

    public static void main(String[] args) {

        // 接口类型的引用变量指向其实现类类型的实例
        List<String> list = new ArrayList<>();
        list.add( "猪悟能" );
        list.add( "沙悟净" );
        list.add( "白骨精" );
        list.add( "孙悟空" );
        System.out.println( list );

        list.add( 0, "孙悟空" );
        System.out.println( list );

        list.set( 1, "猪八戒" );
        System.out.println( list );

        System.out.println( list.indexOf( "孙悟空" ) );
        System.out.println( list.lastIndexOf( "孙悟空" ) );

        String name =  list.get( 2 );
        System.out.println( name );

        System.out.println( list.remove( "白骨精" ) );
        System.out.println( list );

        System.out.println( list.remove( 1 ) );
        System.out.println( list );

        List<String> sub = list.subList( 1, 3 );
        System.out.println( sub );

    }

}
